//
//  iNeedishAppDelegate.m
//  iNeedish
//
//  Created by Felipe Navarro V. on 27-10-09.
//  Copyright deis 2009. All rights reserved.
//

#import "INDefaultStylesheet.h"
#import "iNeedishAppDelegate.h"
#import "TTNeedTableViewController.h"
#import "TTNeedViewController.h"
#import "TTNeedFullViewController.h"
#import "TTUserViewController.h"
#import "TabBarController.h"
#import "MenuController.h"
#import "TTHelpView.h"
#import "AboutController.h"
#import "UserConfigController.h"

@implementation iNeedishAppDelegate


//@synthesize loginViewController;

- (void)applicationDidFinishLaunching:(UIApplication *)application {    
	TTNavigator* navigator = [TTNavigator navigator];
	navigator.supportsShakeToReload = YES;//[[NSUserDefaults standardUserDefaults] boolForKey:@"shake_preference"];
	navigator.persistenceMode = TTNavigatorPersistenceModeTop;

	// Register our stylesheet
	[TTStyleSheet setGlobalStyleSheet:[[[INDefaultStyleSheet alloc]   
										init] autorelease]];
	
	TTURLMap* map = navigator.URLMap;
	[map from:@"*" toViewController:[TTWebController class]];
	[map from:@"in://root" toViewController:[RootController class]];
	[map from:@"in://tabBar" toViewController:[TabBarController class]];	
	
	[map from:@"in://userconfmodal" toModalViewController:[UserConfigController class]];
	[map from:@"in://userconf" toViewController:[UserConfigController class]];

	[map from:@"in://menu/(initWithMenu:)" toSharedViewController:[MenuController class]];
	[map from:@"in://needView/?need=(initWithNeed:)" toSharedViewController:[TTNeedFullViewController class]];
	[map from:@"in://userView/?user=(initWithUser:)" toSharedViewController:[TTUserViewController class]];
	
	[map from:@"in://about" toSharedViewController:[AboutController class]];

	//NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//	NSArray *languages = [defaults objectForKey:@"AppleLanguages"];
//	NSString *currentLanguage = [languages objectAtIndex:0];
//	TTLOG(@"Current language: %@", currentLanguage);
	
	
	if(![navigator restoreViewControllers]) {
		[navigator openURL:@"in://tabBar" animated:NO];
	}
}

- (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)URL {
	[[TTNavigator navigator] openURL:URL.absoluteString animated:NO];
	return YES;
}

- (void)applicationWillTerminate:(UIApplication *)application {
	TTLOG(@"This is the END");
//	[[NSUserDefaults standardUserDefaults] setObject:nil forKey:@"INSessionSecret"];
}




@end
